# Name: Makefile
# Project uBOOT
# 2007-01-07 me@anyma.ch
#
# based on
# Makefile for AVRUSBBoot
# Modified by: Thomas Fischl
# Modified: 2006-06-25

# Original file by: Christian Starkjohann
# Creation Date: 2004-12-29
# Tabsize: 4
# Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
# License: Proprietary, free under certain conditions. See Documentation.
# This Revision: $Id: Makefile 147 2006-03-01 17:33:03Z cs $

BOOTLOADER_ADDRESS = 1800

LDFLAGS += -Wl,--section-start=.text=$(BOOTLOADER_ADDRESS)

UISP = uisp -dprog=stk500 -dserial=`echo /dev/tty.[Uu][Pp]*` -dpart=atmega8

# The two lines above are for "uisp" and the AVR910 serial programmer connected
# to a Keyspan USB to serial converter to a Mac running Mac OS X.
# Choose your favorite programmer and interface.

COMPILE = avr-gcc -Wall -Os -Iusbdrv -I. -mmcu=atmega8 
#-DDEBUG_LEVEL=2
# NEVER compile the final product with debugging! Any debug output will
# distort timing so that the specs can't be met.

OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o uBOOT.o
# Note that we link usbdrv.o first! This is required for correct alignment of
# driver-internal global variables!


# symbolic targets:
all:	uBOOT.hex

.c.o:
	$(COMPILE) -c $< -o $@

.S.o:
	$(COMPILE) -x assembler-with-cpp -c $< -o $@
# "-x assembler-with-cpp" should not be necessary since this is the default
# file type for the .S (with capital S) extension. However, upper case
# characters are not always preserved on Windows. To ensure WinAVR
# compatibility define the file type manually.

.c.s:
	$(COMPILE) -S $< -o $@

flash:	all
	$(UISP) --erase --upload --verify if=uBOOT.hex

fuse:
	$(UISP) --wr_fuse_h=0xc8
	$(UISP) --wr_fuse_l=0xef
	
avrdude: 
	avrdude -c avr910 -p atmega8 -U flash:w:uBOOT.hex


clean:
	rm -f uBOOT.hex uBOOT.lst uBOOT.obj uBOOT.cof uBOOT.list uBOOT.map uBOOT.eep.hex uBOOT.bin *.o usbdrv/*.o uBOOT.s usbdrv/oddebug.s usbdrv/usbdrv.s

# file targets:
uBOOT.bin:	$(OBJECTS)
	$(COMPILE) -o uBOOT.bin $(OBJECTS) $(LDFLAGS)

uBOOT.hex:	uBOOT.bin
	rm -f uBOOT.hex uBOOT.eep.hex
	avr-objcopy -j .text -j .data -O ihex uBOOT.bin uBOOT.hex
	./checksize uBOOT.bin
# do the checksize script as our last action to allow successful compilation
# on Windows with WinAVR where the Unix commands will fail.

disasm:	uBOOT.bin
	avr-objdump -d uBOOT.bin

cpp:
	$(COMPILE) -E uBOOT.c
	
download:
	$(UISP) --download
